import {ConnectProps} from "@/models/connect";
import {message} from "antd";

export interface queryModel extends ConnectProps {
  code: {
    key: String,
    desc: String,
  },
  attach: any,
}

export const queryUse = (query: queryModel) => {
  try {
    if (query.code.key === "code_sys_ok") {
      return query.attach;
    } else {
      if (window["errorFlag"] !== "登录已过期,请重新登录") {
        message.error(
          query.code.desc, 3
        )
        window["errorFlag"] = "登录已过期,请重新登录";
        setInterval(() => {
          window["errorFlag"] = "";
        }, 3000)
      }
      return null;
    }
  } catch (e) {
    message.error(
      e.toString(), 3
    )
    return null;
  }
}
export const queryUseUpdate = (query: queryModel) => {
  try {
    if (query.code.key === "code_sys_ok") {
      message.success(
        query.code.desc, 3
      )
      return true;
    } else {
      if (window["errorFlag"] !== "登录已过期,请重新登录") {
        message.error(
          query.code.desc, 3
        )
        window["errorFlag"] = "登录已过期,请重新登录";
        setInterval(() => {
          window["errorFlag"] = "";
        }, 3000)
      }
      return false;
    }
  } catch (e) {
    message.error(
      e.toString(), 3
    )
    return null;
  }
}
